package com.databuff;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则
 * @package com.databuff
 * @company: dacheng
 * @author: zlh
 * @createDate: 2022/5/16
 */
public class PatternRegEx {
    public static void main(String[] args) {
        DemoPhone();
        // 提取数字
        String expr = "[^0-9]+";
        String content = "qerwrteryrty";
        Pattern pattern = Pattern.compile(expr);
        String[] split = pattern.split(content);
        StringBuilder builder = new StringBuilder();
        if (split.length == 0){
            builder.append(1000);
        }
        for (String aSplit : split) {
            builder.append(aSplit);
        }
        System.out.println("提取的数字是："+Long.valueOf(builder.toString()));
    }

    private static void DemoPhone() {
        String expr = "^(?:(?:\\+|00)86)?1[3-9]\\d{9}$";
        Pattern compile = Pattern.compile(expr);
        Matcher matcher = compile.matcher("15658100218");
        if (matcher.find()){
            System.out.println("这是电话号码！");
        }else {
            System.out.println("这不是电话号码！");
        }
    }
}
